import requests
#  使用get方式发送请求
#  在地址栏拼接参数 www.xxx.com/?key1=value1&key2=value2
#   {key1:value1}
# Requests除了这种方式，还有可以使用params传参
# response = requests.get("https://www.baidu.com/s?wd=python")
#data = {'wd':"java"}
#response=requests.get("https://www.baidu.com/s?wd=python")
#print(response.url)
#print(response.text)

# 直接向百度发送请求，获取不到页面
# rep = requests.get("https://www.baidu.com",header=header)
# 需要添加用户代理放进请求里头，则可以正常得到响应
headers={
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0"
}
rep = requests.get("https://www.baidu.com", headers=headers)
print(rep.content.decode("utf-8"))